﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Text.RegularExpressions;
using Total_Mayhem.Common;
using System.Diagnostics;

namespace Total_Mayhem.Other
{

    public partial class DateTimeEventConfig : MayhemWpf.UserControls.WpfConfiguration
    {
        public DateTimeEventConfig(DateTime? StartDate=null)
        {
            InitializeComponent();
            if (StartDate == null)
            {
                var dt = DateTime.Now;
                this.StartDate = dt.AddSeconds(60 - dt.Second);
            }
            else
            {
                this.StartDate = StartDate.Value;
            }
        }

        public override void OnLoad()
        {
            CanSave = true;
            //hlHelp.RequestNavigate += new RequestNavigateEventHandler(Network.Hyperlink_HandleClick);
            dtStartDate.Value = StartDate;
            cmbRepeat_SelectionChanged(null, null);
        }

        private string strTitle = "Date / Time Event";
        public override string Title { get {return strTitle;} }

        public DateTime StartDate
        {
            get;
            set;
        }

        private void btnTest_Click(object sender, RoutedEventArgs e)
        {
            //textInvalid.Text = string.Format("Executing command: {0}",NirCmd);
            //textInvalid.Visibility = System.Windows.Visibility.Visible;

            //string strArgs = NirCmd.Replace("nircmd.exe ","");
            //Misc.ExecuteNirCmd(strArgs);
        }

        private void cmbCommand_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            /*if (cmbCommand.SelectedItem != null)
            {
                ComboBoxItem i = (cmbCommand.SelectedItem as ComboBoxItem);
                if (i != null)
                {
                    NirCmd = (string)i.Tag;
                }
            }*/
        }

        private void cmbRepeat_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (cmbRepeat != null && cmbRepeatEvery != null && cmbRepeat.SelectedItem != null)
            {
                ComboBoxItem i = cmbRepeat.SelectedItem as ComboBoxItem;
                txtRepeatsEveryLabel.Text = i.Tag.ToString();

                //Set Defaults
                tbRepeatsEvery.Visibility = System.Windows.Visibility.Hidden;
                cmbRepeatEvery.Visibility = System.Windows.Visibility.Visible;
                spRepeatOn.Visibility = System.Windows.Visibility.Hidden;
                txtRepeatOn.Visibility = System.Windows.Visibility.Hidden;
                txtDayOfMonth.Visibility = System.Windows.Visibility.Hidden;

                switch (cmbRepeat.SelectedIndex)
                {
                    case 0:
                        //Never
                        cmbRepeatEvery.IsEnabled = false;
                        break;
                    case 1:
                        //Interval
                        cmbRepeatEvery.IsEnabled = false;
                        tbRepeatsEvery.Visibility = System.Windows.Visibility.Visible;
                        cmbRepeatEvery.Visibility = System.Windows.Visibility.Hidden;
                        break;
                    case 2:
                        //Daily
                        cmbRepeatEvery.IsEnabled = true;
                        break;
                    case 3:
                        //Weekly
                        cmbRepeatEvery.IsEnabled = true;
                        spRepeatOn.Visibility = System.Windows.Visibility.Visible;
                        txtRepeatOn.Visibility = System.Windows.Visibility.Visible;
                        break;
                    case 4:
                        //Monthly
                        cmbRepeatEvery.IsEnabled = true;
                        txtRepeatOn.Visibility = System.Windows.Visibility.Visible;
                        txtDayOfMonth.Visibility = System.Windows.Visibility.Visible;
                        break;
                    default:
                        break;
                }
            }
        }

        private void cmbRepeatEvery_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }

        private void tbRepeatsEvery_TextChanged(object sender, TextChangedEventArgs e)
        {

        }

        /*
        public override void OnLoad()
        {
            //Set wpf element text here
            textBoxName.Text = ComputerName;
            if (string.IsNullOrEmpty(textBoxName.Text)) { textBoxName.Text = "android-bc685d7e8081788a"; } //TODO: Remove before release
            var saved = cmbInterval.Items.Cast<ComboBoxItem>().FirstOrDefault(i => i.Tag.ToString() == IntervalinSeconds.ToString());
            if (saved != null)
            {
                saved.IsSelected = true;
            }
            //var saved2 = cmbWait.Items.Cast<ComboBoxItem>().FirstOrDefault(i => i.Tag.ToString() == WaitinMilliSeconds.ToString());
            //if (saved2 != null)
            //{
            //    saved2.IsSelected = true;
            //}
        }

         */
    }
}
